import { get } from '../../http/axios'

export default {
    // 命名空间
    namespaced: true,
    // 状态
    state: {
        dataList: {}
    },
    // 过滤器
    getters: {
        confirmed(state) {
            var res = 0;
            if (state.dataList.list) {
                state.dataList.list.forEach((item) => {
                    res +=item.confirmed
                });
                // console.log(res);
                return res;
            }
        },
        suspected(state) {
            var res = 0;
            if (state.dataList.list) {
                state.dataList.list.forEach((item) => {
                    res +=item.suspected
                });
                // console.log(res);
                return res;
            }
        },
        dead(state) {
            var res = 0;
            if (state.dataList.list) {
                state.dataList.list.forEach((item) => {
                    res +=item.dead
                });
                // console.log(res);
                return res;
            }
        },
        cure(state) {
            var res = 0;
            if (state.dataList.list) {
                state.dataList.list.forEach((item) => {
                    res +=item.cure
                });
                // console.log(res);
                return res;
            }
        },
        severe(state) {
            var res = 0;
            if (state.dataList.list) {
                state.dataList.list.forEach((item) => {
                    res +=item.severe
                });
                // console.log(res);
                return res;
            }
        },
        outside(state) {
            var res = 0;
            if (state.dataList.list) {
                state.dataList.list.forEach((item) => {
                    res +=item.outside
                });
                // console.log(res);
                return res;
            }
        }

    },
    // 突变 -> 改变state中变量的唯一方式
    mutations: {
        set_dataList(state, dataList) {
            // 设置数据列表
            state.dataList = dataList;
        }
    },
    // 动作 -> methods,发送请求
    actions: {
        async page_query(context, params) {
            let res = await get('/epidemic/pageQuery', params);
            // console.log(res.data.list);
            context.commit('set_dataList', res.data)
            return res.data
        },
        async deleteById({commit}, params) {
            let res = await get('/epidemic/deleteById', params);
            // console.log(res.data);
            return res;
        }
        
    }
}